package com.ayu.shortlink.admin.controller;

import com.ayu.shortlink.admin.common.convention.result.Result;
import com.ayu.shortlink.admin.common.convention.result.Results;
import com.ayu.shortlink.admin.dto.req.CouponTaskCreateReqDTO;
import com.ayu.shortlink.admin.dto.req.CouponTaskPageQueryReqDTO;
import com.ayu.shortlink.admin.dto.req.UserExcelCreateReqDTO;
import com.ayu.shortlink.admin.dto.resp.CouponTaskPageQueryRespDTO;
import com.ayu.shortlink.admin.dto.resp.CouponTaskQueryRespDTO;
import com.ayu.shortlink.admin.service.CouponTaskService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 发送优惠券模块控制器
 */
@RestController
@RequiredArgsConstructor
public class CouponTaskController {
    private final CouponTaskService couponTaskService;

    /**
     * 创建用户发放的Excel
     */
    @PostMapping("/api/short-link/admin/v1/coupon-task/user-excel/create")
    public Result<Void> createUserExcel(@RequestBody UserExcelCreateReqDTO requestParam){
        couponTaskService.createUserExcel(requestParam);
        return Results.success();
    }

    /**
     * 创建优惠券发送任务
     */
    @PostMapping("/api/short-link/admin/v1/coupon-task/create")
    public Result<Void> createCouponTask(@RequestBody CouponTaskCreateReqDTO requestParam){
        couponTaskService.createCouponTask(requestParam);
        return Results.success();
    }

    /**
     * 查询优惠券任务详细
     */
    @GetMapping("/api/short-link/admin/v1/coupon-task/query")
    public Result<CouponTaskQueryRespDTO> queryCouponTask(String couponTaskId){
        return Results.success(couponTaskService.queryCouponTask(couponTaskId));
    }

    /**
     * 分页查询优惠券任务
     */
    @GetMapping("/api/short-link/admin/v1/coupon-task/page")
    public Result<IPage<CouponTaskPageQueryRespDTO>> pageQueryCouponTask(CouponTaskPageQueryReqDTO requestParam){
        return Results.success(couponTaskService.pageQueryCouponTask(requestParam));
    }
}
